home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / c / metre.lha / metre.h < prev    next >
C/C++ Source or Header  |  1994-09-07  |  8KB  |  197 lines

  1. /*************************************************************
  2.    Copyright (c) 1993,1994 by Paul Long  All rights reserved.
  3. **************************************************************/
  4.  
  5. /*************************************************************
  6.    metre.h -   This header file contains #defines,
  7.                typedefs, and externs that are used
  8.                by the rules code to interface with
  9.                the parser.
  10. **************************************************************/
  11.  
  12.  
  13. #ifndef _METRE_H_
  14. #define _METRE_H_
  15.  
  16. #include <stdio.h>
  17.  
  18.  
  19. /* Define TRUE and FALSE if environment doesn't. */
  20. #ifndef TRUE
  21. #define TRUE (0==0)
  22. #define FALSE (!TRUE)
  23. #endif
  24. typedef int BOOLEAN;
  25.  
  26. /*
  27.    Project information.  A project consists of one or more modules
  28.    (source files).
  29. */
  30. typedef struct {
  31.    BOOLEAN begin;          /* Set to whether beginning of the project. */
  32.    BOOLEAN end;            /* Set to whether end of the project. */
  33. } PRJ;
  34.  
  35. /*
  36.    Module information.  In Metre, a module is currently the same thing as
  37.    a source file.
  38. */
  39. typedef struct {
  40.    BOOLEAN begin;          /* Set to whether beginning of a source module
  41.                               has been encountered. */
  42.    BOOLEAN end;            /* Set to whether end of a source module (a file
  43.                               and all of its included files) has been
  44.                               reached. */
  45.    struct {
  46.       unsigned total;      /* Set to the total number of lines in a module. */
  47.       unsigned com;        /* Set to the number of comment lines in a module. */
  48.       unsigned white;      /* Set to the number of whitespace lines in a
  49.                               module. */
  50.       unsigned exec;       /* Set to the number of executable lines in a
  51.                               module. */
  52.    } lines;
  53.    unsigned decisions;     /* Set to the number of binary decision points in a
  54.                               module. */
  55.    unsigned functions;     /* Set to the number of functions defined in a
  56.                               module. */
  57. } MOD;
  58.  
  59. /* Function information. */
  60. typedef struct {
  61.    BOOLEAN begin;          /* Set to whether beginning of a function has
  62.                               been found. */
  63.    BOOLEAN end;            /* Set to whether end of a function has been
  64.                               found. */
  65.    struct {
  66.       unsigned total;      /* Set to the total number of lines in a function. */
  67.  
  68.       unsigned com;        /* Set to the number of comment lines in a
  69.                               function. */
  70.       unsigned white;      /* Set to the number of whitespace lines in a
  71.                               function. */
  72.       unsigned exec;       /* Set to the number of executable lines in a
  73.                               function. */
  74.    } lines;
  75.    unsigned high;          /* Set to the number of high-level statements found
  76.                               in the definition of a C function. */
  77.    unsigned low;           /* Set to the number of low-level statements found
  78.                               in the definition of a C function. */
  79.    unsigned decisions;     /* Set to the number of binary decision points in a
  80.                               function. */
  81. } FCN;
  82.  
  83. /* Statement information. */
  84. typedef struct {
  85.    BOOLEAN end;            /* Set to whether end of a statement has been
  86.                               found. */
  87.    unsigned depth;         /* Set to the logical depth of a statement, i.e.,
  88.                               its nesting level within if-, for-, while-, and
  89.                               do-statements. */
  90.    BOOLEAN is_comp;        /* Set to whether is a compound statement. */
  91.    BOOLEAN is_expr;        /* Set to whether is an expression statement. */
  92.    BOOLEAN is_high;        /* Set to whether is a compound, selection, or
  93.                               iteration statement. */
  94.    BOOLEAN is_iter;        /* Set to whether is an iteration statement. */
  95.    BOOLEAN is_jump;        /* Set to whether is a jump statement. */
  96.    BOOLEAN is_label;       /* Set to whether is a labeled statement. */
  97.    BOOLEAN is_low;         /* Set to whether is an expression or jump
  98.                               statement. */
  99.  
  100.    BOOLEAN is_select;      /* Set to whether is a selection statement. */
  101. } STM;
  102.  
  103. /* Line information. */
  104. typedef struct {
  105.    unsigned number;        /* Set to the number of the current line, relative
  106.                               to the start of the current file. */
  107.    BOOLEAN end;            /* Set to whether a newline character has been
  108.                               found. */
  109.    BOOLEAN is_comment;     /* Set to whether line has no C code and either
  110.                               contains a comment or is contained within a
  111.                               comment.  The comment must contain text to qualify
  112.                               as a real comment. */
  113.    BOOLEAN is_white;       /* Set to whether line consists entirely of whitespace
  114.                               tabs & spaces), or is a comment line without any
  115.                               text. */
  116.    BOOLEAN is_exec;        /* Set to whether line contains code that is
  117.                               executable. */
  118.    unsigned statements;    /* Set to the number of statements on the current
  119.                                  line. */
  120.    BOOLEAN is_mixed_indent;   /* Set to whether line is indented with both space
  121.                                  and tab characters. */
  122. } LIN;
  123.  
  124. /* Lexical information. */
  125. typedef struct {
  126.    int nonstandard;        /* Whenever a character is found that is not in the
  127.                               standard C set, the value of this variable is set
  128.                               to the integer representation of the nonstandard
  129.                               character. */
  130. } LEX;
  131.  
  132. /*
  133.    Extern declarations for the structs through which the parser provides
  134.    information to the rules.
  135. */
  136. extern PRJ prj;
  137. extern MOD mod;
  138. extern FCN fcn;
  139. extern STM stm;
  140. extern LIN lin;
  141. extern LEX lex;
  142.  
  143. /* FILE pointer to where any output should be directed by the rules. */
  144. extern FILE *out_fp;
  145.  
  146. /* Returns pointer to current function name. */
  147. extern char *fcn_name(void);
  148.  
  149. /* Returns pointer to current module (file) name. */
  150. extern char *mod_name(void);
  151.  
  152. /* Returns pointer to current source line. */
  153. extern char *line(void);
  154.  
  155. /*
  156.    Returns pointer to string that "points" to the parser's current location in
  157.    source.  E.g.,
  158.                                    -
  159.    Useful in error messages.  The parser uses this function for syntax errors,
  160.    but it could also be used by a rule.
  161. */
  162. extern char *marker(void);
  163.  
  164. /* Returns pointer to current token (lexeme, actually) in the source. */
  165. extern char *token(void);
  166.  
  167. /*
  168.    Returns TRUE when the indicated keyword or identifier, e.g., "while"
  169.    or "myBuffer", respectively, is encountered.  Can be used as a
  170.    trigger in a rule.
  171. */
  172. extern BOOLEAN keyword(char *);
  173. extern BOOLEAN identifier(char *);
  174.  
  175. /*
  176.    Returns pointer to the part of an option following the "=".  E.g.,
  177.    for -Xabc=def, it would point to the "def" part.
  178. */
  179. extern char *str_option(char);
  180.  
  181. /*
  182.    Returns TRUE if the indicated option character was specified on the
  183.    command line.  E.g., for -S, would return TRUE for option('S').
  184. */
  185. extern int option(char);
  186.  
  187. /*
  188.    Used by rules to indicate a fatal error or warning.  Expects a
  189.    fatal-error or warning number that the programmer can make up,
  190.    followed by a format string and other arguments, just like printf().  E.g.,
  191.    warn(0, "goto statement used (%u time%s)", fcn_gotos, NUMBER(fcn_gotos));
  192. */
  193. extern void fatal(int, char *, ...);
  194. extern void warn(int, char *, ...);
  195.  
  196. #endif
  197.